//
//  CreateResumeVC.m
//  u76ho
//
//  Created by m-air-01 on 15/12/29.
//  Copyright © 2015年 LV. All rights reserved.
//

#import "CreateResumeVC.h"
#import "CreateResumeTableViewCell.h"
#import "ChosePrivinceViewController.h"
#import "ChosePositionViewController.h"
#import "WorkYearsViewController.h"
#import "HopeMoneyViewController.h"
#import "NameViewController.h"
#import "PhoneNumberViewController.h"
#import "PartAlumViewController.h"
#import "ScanResumeViewController.h"


@interface CreateResumeVC ()
<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UITextViewDelegate,ChosePrivinceDelegae,workYearsDelegate,HopeMoneyDelegate,UIActionSheetDelegate,ChangePhoneNumDelegate,ChangeNameDelegate,TongBuAlumDelegate,UIAlertViewDelegate>
{
    UITableView * _tableView;
    int mytag;
    UIView * tableHeaderV;
    UIView * sectionOne;
    UIView * sectionTwo;
    UIButton * saveBtn;//保存按钮
    
    ResumeAddModel * scanResumeModel;//预览的简历
}
@property (nonatomic,strong) ResumeAddModel * addResumeModel;//添加的简历

@end

@implementation CreateResumeVC
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];

    self.navigationController.navigationBarHidden = NO;
}
-(void)viewWillDisappear:(BOOL)animated
{
    UITextField * resumeNameTextField = (UITextField *)[self.view viewWithTag:1];
    [resumeNameTextField resignFirstResponder];
    
    [super viewWillDisappear:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self main];
    [self addRightItem];
    self.navigationItem.title = @"创建简历";
   // [self addNavgationBar];
    [self addBackItem];
    
    
    // Do any additional setup after loading the view.
}
-(void)main
{
    _addResumeModel = [[ResumeAddModel alloc]init];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectedZhiweiNotification:) name:@"selectedZhiweiNotification" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(choosePSQNoti:) name:@"choosePSQNoti" object:nil];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStyleGrouped];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    
    if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [_tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [_tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    
    _tableView.tableFooterView = [self createTableFooterView];
//    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.separatorColor = UIColorFromRGB(0xf1f3f2);
    [_tableView registerNib:[UINib nibWithNibName:@"CreateResumeTableViewCell" bundle:nil] forCellReuseIdentifier:@"CreateResumeTableViewCell"];
    _tableView.backgroundColor = UIColorFromRGB(0xf1f3f2);
    
    
    
    
    [self.view addSubview:_tableView];
    self.automaticallyAdjustsScrollViewInsets = NO;
    if (_isEditing) {
        [self editingResume];
    }
    else
    {
        _addResumeModel.ispic = @"0";
        _addResumeModel.mypics = @"";
    }
    [self registerForKeyboardNotifications];
    
}
-(void)editingResume
{
    __weak typeof(self)weakSelf = self;
    [U76HONet editResumeWithAction:@"" code:[Singleton share].code rid:_rid andDataBlock:^(EditResumeModel *model) {
        NSLog(@"编辑简历获取数据成功列");
        
        UITextField * titleField = (UITextField *)[weakSelf.view viewWithTag:1];
        titleField.text = model.title;
        _addResumeModel.title = model.title;
        
        UITextField * realNameField = (UITextField *)[weakSelf.view viewWithTag:2];
        realNameField.text = model.realname;
        _addResumeModel.realname = model.realname;
        
        UITextField * sexField = (UITextField *)[weakSelf.view viewWithTag:3];
        if ([model.sex isEqualToString:@"1"]) {
            sexField.text = @"男";
        }
        else if ([model.sex isEqualToString:@"2"])
        {
            sexField.text = @"女";
        }
        _addResumeModel.sex = model.sex;
        
        UITextField * telFied = (UITextField *)[weakSelf.view viewWithTag:4];
        telFied.text = model.tel;
        _addResumeModel.tel = model.tel;
        
        UITextField * workYearField = (UITextField *)[weakSelf.view viewWithTag:5];
        workYearField.text = model.years;
        _addResumeModel.workyear = model.workyear;
        
        UITextField * birthdayField = (UITextField *)[weakSelf.view viewWithTag:6];
        NSString * str = model.birthday;
        NSMutableArray * mArr = [[NSMutableArray alloc]init];
        
        NSString * sub1 = [str substringToIndex:4];
        [mArr addObject:sub1];
        NSString * sub2 = [str substringWithRange:NSMakeRange(4, 2)];
        [mArr addObject:sub2];
        NSString * sub3 = [str substringWithRange:NSMakeRange(6, 2)];
        [mArr addObject:sub3];
        
        NSString * birthday = [mArr componentsJoinedByString:@"-"];
        birthdayField.text = birthday;
        _addResumeModel.birthday = model.birthday;
        
        UITextField * noaddrField = (UITextField *)[weakSelf.view viewWithTag:7];
        noaddrField.text = model.nowaddrname;
        _addResumeModel.nowaddr = model.nowaddr;
        
        UITextField * workCityField = (UITextField *)[weakSelf.view viewWithTag:8];
        workCityField.text = model.workcityname;
        _addResumeModel.workcity = model.workplace;
        
        UITextField * homeAddrField = (UITextField *)[weakSelf.view viewWithTag:9];
        homeAddrField.text =model.homeaddrname;
        _addResumeModel.homeaddr = model.homeaddr;
        
        UITextField * dutyField = (UITextField *)[weakSelf.view viewWithTag:10];
        dutyField.text = model.dutyname;
        _addResumeModel.dutyid = model.dutyid;
        
        UITextField * salaryField = (UITextField *)[weakSelf.view viewWithTag:11];
        salaryField.text = model.salaryname;
        _addResumeModel.salary = model.salary;
        
        UITextView * textView = (UITextView *)[weakSelf.view viewWithTag:12];
        textView.text = model.intro;
        _addResumeModel.intro = model.intro;
        
        _addResumeModel.ispic = model.ispic;
        
        _addResumeModel.mypics = model.mypics;
        if ([_addResumeModel.ispic isEqualToString:@"0"]) {
            
        }
        else
        {
            UIButton * saveBtn = (UIButton *)[self.view viewWithTag:513];
            saveBtn.selected = YES;
        }
        for (int i = 0; i< 2; i++) {
            UILabel * lab = (UILabel *)[self.view viewWithTag:i+20];
            lab.hidden = YES;
        }
        
    }];
}
-(void)modifyResumeWithmodel:(ResumeAddModel *)model
{
    
    
//    [MMProgressHUD setPresentationStyle:MMProgressHUDPresentationStyleFade];
//    [MMProgressHUD showWithTitle:@"正在上传" status:@""];
//    
//    

    [LoadingView loadingView];
    
    __weak typeof(self)weakSelf = self;
    [U76HONet modifyRusumeWithAction:@"" model:model andDataBlock:^(NSDictionary *dic) {
        NSLog(@"保存编辑简历成功了");
        _editingBlock();
        
        
        saveBtn.userInteractionEnabled = NO;
        saveBtn.alpha = 0.4;

        
//        [MMProgressHUD dismissWithSuccess:@"成功上传"];
        
        [LoadingView removeLoadingView];
        
        [Singleton alerSendMessage:@"保存成功"];

        [weakSelf performSelector:@selector(GoTOBack:) withObject:nil afterDelay:1.0];

       
    }];
}
-(void)GoTOBack:(id)sender{

    [self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];

}
-(void)resumeAddWithAction:(ResumeAddModel *)model
{
    
//    [MMProgressHUD setPresentationStyle:MMProgressHUDPresentationStyleFade];
//    [MMProgressHUD showWithTitle:@"正在上传" status:@""];
//    
//    
    
    [LoadingView loadingView];
    
    __weak typeof(self)weakSelf = self;
    [U76HONet resumeAddWithAction:@"" model:model andDataBlock:^(NSDictionary *dic) {
        NSLog(@"添加简历成功了");
        _createBlock();
        

//        [MMProgressHUD dismissWithSuccess:@"成功上传"];
        
        saveBtn.userInteractionEnabled = NO;
        saveBtn.alpha = 0.4;
        
        [LoadingView removeLoadingView];
        
        [Singleton alerSendMessage:@"保存成功"];

        
         [weakSelf performSelector:@selector(GoTOBack:) withObject:nil afterDelay:1.0];

//        [weakSelf dismissViewControllerAnimated:YES completion:nil];
//        [weakSelf.navigationController popViewControllerAnimated:YES];

    }];
}
//去拉取相册
-(void)getAlumData
{
    
    [U76HONet minePictureWithaction:@"" code:[Singleton share].code andDataBlock:^(NSArray *arr) {
//        if (dataSource.count!=0) {
//            [dataSource removeAllObjects];
//        }
//        [dataSource addObjectsFromArray:arr];
//        [_collectionView reloadData];
        NSLog(@"获取我的图片库数据成功了");
        NSMutableArray * tempArr = [[NSMutableArray alloc]init];
        for (int i = 0; i<arr.count; i++) {
            PictureModel * model = arr[i];
            [tempArr addObject:model.ids];
        }
        NSString * mypicStr = [tempArr componentsJoinedByString:@"|"];
        _addResumeModel.mypics = mypicStr;
        
    }];
}

#pragma mark - _tableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CreateResumeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"CreateResumeTableViewCell"];
    
    NSString * string1 = nil;
    if (indexPath.section == 0) {
        string1 = @"简历名称";
        cell.isHiddenSecLab = @"YES";
    }
    else if (indexPath.section == 1) {
        string1 = @"基本信息 ";
    }
    else if(indexPath.section == 2)
    {
        string1 = @"个人简历 ";
    }
    cell.backgroundColor = UIColorFromRGB(0xf1f3f2);
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.firstLab.text = string1;
    return cell;
    
//    static NSString * ID = @"cell";
//    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
//    if (cell == nil) {
//        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
//    }
//    
//    for (id i in cell.subviews) {
//        if ([i isKindOfClass:[UILabel class]]) {
//            [i removeFromSuperview];
//        }
//    }
//    
//    NSString * string1 = nil;
//    UILabel * nameLab = [[UILabel alloc]initWithFrame:CGRectMake(SIZETO6W(15), 0, 80, cell.height)];
//    nameLab.backgroundColor = [UIColor redColor];
//    if (indexPath.section == 0) {
//        string1 = @"简历名称";
//    }
//    else if (indexPath.section == 1) {
//        string1 = @"基本信息 ";
//        UILabel * needLab = [[UILabel alloc]initWithFrame:CGRectMake(nameLab.right+5, (cell.height - 20)/2, 60, 20)];
//        needLab.textAlignment = NSTextAlignmentCenter;
//        needLab.textColor = [UIColor redColor];
//        needLab.layer.masksToBounds = YES;
//        needLab.text = @"必填";
//        needLab.layer.borderColor = [[UIColor redColor] CGColor];
//        needLab.layer.borderWidth = 1.0f;
//        needLab.layer.cornerRadius = 20;
//        [cell addSubview:needLab];
//    }
//    else if(indexPath.section == 2)
//    {
//        string1 = @"个人简历 ";
//        UILabel * needLab = [[UILabel alloc]initWithFrame:CGRectMake(nameLab.right+5, (cell.height - 20)/2, 30, 20)];
//        needLab.textAlignment = NSTextAlignmentCenter;
//        needLab.textColor = [UIColor redColor];
//        needLab.layer.masksToBounds = YES;
//        needLab.text = @"必填";
//        needLab.layer.borderColor = [[UIColor redColor] CGColor];
//        needLab.layer.borderWidth = 1.0f;
//        needLab.layer.cornerRadius = 20;
//        [cell addSubview:needLab];
//
//    }
//    nameLab.text = string1;
//    [cell addSubview:nameLab];
//    cell.backgroundColor = UIColorFromRGB(0xf1f3f2);
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    
//    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return [self createTabelHeaderView];
    }
    else if (section == 1) {
        return [self createSection0View];
    }
    else if(section == 2)
    {
        return [self createSection1View];
    }
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return 50;
    }
    else if (section == 1) {
        return 400;
    }
    else
    {
        return 110;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1;
}
#pragma mark - createHeaderView
-(UIView *)createTabelHeaderView
{
    if (tableHeaderV) {
        
    }
    else
    {
    
    tableHeaderV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    tableHeaderV.backgroundColor = UIColorFromRGB(0xf1f3f2);
    UITextField * resumeName = [[UITextField alloc]initWithFrame:CGRectMake(SIZETO6W(20), 0, SCREEN_WIDTH-SIZETO6W(15)*2, 50) ];
//    resumeName.layer.masksToBounds = YES;
//    resumeName.layer.borderWidth = 1;
    resumeName.tag = 1;
    resumeName.delegate = self;
    resumeName.layer.borderColor = [[UIColor blackColor] CGColor];
    resumeName.placeholder = @"请输入简历名称";
    resumeName.backgroundColor = [UIColor whiteColor];
    [resumeName setValue:UIColorFromRGB(0xbbbfc3) forKeyPath:@"_placeholderLabel.textColor"];
    [resumeName addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventEditingChanged];
    [tableHeaderV addSubview:resumeName];
    }
    return tableHeaderV;
}
-(UIView *)createTableFooterView
{
    UIView * tableFooterV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 150)];
    UIButton * selectedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    selectedBtn.frame = CGRectMake(20, 20, 40, 40);
    [selectedBtn setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    selectedBtn.tag = 513;
    [selectedBtn setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
    [selectedBtn addTarget:self action:@selector(selectedAction:) forControlEvents:UIControlEventTouchUpInside];
    [tableFooterV addSubview:selectedBtn];
    
    UILabel * contentLab = [[UILabel alloc]initWithFrame:CGRectMake(selectedBtn.right, 15, SCREEN_WIDTH-selectedBtn.right-50, 60)];
    contentLab.font = [UIFont systemFontOfSize:14];
    contentLab.text =  @"将\"我的职场图片库\"同步到\"我的简历\"，更多招聘方看到您！保存简历后可直接同步成功";
    contentLab.textColor = UIColorFromRGB(0x94999f);
    contentLab.numberOfLines = 0;
    contentLab.userInteractionEnabled = YES;
    [tableFooterV addSubview:contentLab];
    saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.frame = CGRectMake(SIZETO6W(15), contentLab.bottom, SCREEN_WIDTH-SIZETO6W(15)*2, 50);
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    saveBtn.tag = 504;
    saveBtn.layer.masksToBounds = YES;
    saveBtn.layer.cornerRadius = 20;
    [saveBtn addTarget:self action:@selector(saveBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveBtn setBackgroundColor:UIColorFromRGB(0x6ec844)];
    [tableFooterV addSubview:saveBtn];
    
    UIImageView * arrowImg = [[UIImageView alloc]initWithFrame:CGRectMake(tableFooterV.frame.size.width-30, contentLab.top+30-15/2, 9, 15)];
    arrowImg.userInteractionEnabled = YES;
    arrowImg.image = [UIImage imageNamed:@"all-跳转图标"];
    [tableFooterV addSubview:arrowImg];
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapActionTwo:)];
    tap.numberOfTapsRequired = 1;
    tap.numberOfTouchesRequired = 1;
    
    [arrowImg addGestureRecognizer:tap];
    
    UITapGestureRecognizer * tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapActionThree:)];
    tap2.numberOfTapsRequired = 1;
    tap2.numberOfTouchesRequired = 1;
    [contentLab addGestureRecognizer:tap2];
    
    return tableFooterV;
}
-(UIView *)createSection0View
{
    if (sectionOne) {
        
    }
    else
    {
        sectionOne = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 400)];
        UIView * subV = [[UIView alloc]initWithFrame:CGRectMake(15, 5, SCREEN_WIDTH-30, 400)];
        subV.backgroundColor = [UIColor whiteColor];
    //    subV.layer.masksToBounds = YES;
    //    subV.layer.borderWidth = 0.5;
    //    subV.layer.borderColor = [[UIColor blackColor]CGColor];
        [sectionOne addSubview:subV];
        NSMutableArray * arr = [[NSMutableArray alloc]init];
        [arr addObjectsFromArray:@[@"姓       名:",@"性       别:",@"联系电话:",@"工作年限:",@"出生日期:",@"现居住地:",@"想工作地:",@"籍       贯:",@"职位类别:",@"期望薪资:"]];
        for (int i = 0; i<arr.count;i++) {
            
            UIView * lastSubV = [[UIView alloc]initWithFrame:CGRectMake(0,i*40 , SCREEN_WIDTH, 40)];
            lastSubV.userInteractionEnabled = YES;
            lastSubV.tag = 100+i;
            [subV addSubview:lastSubV];
            
            UILabel * nameLab = [[UILabel alloc]initWithFrame:CGRectMake(10, i*40, 90, 40)];
            nameLab.text = arr[i];
            [subV addSubview:nameLab];
            subV.userInteractionEnabled = YES;
            UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(nameLab.right, nameLab.top, subV.frame.size.width-nameLab.right-50, 40)];
            textField.tag = i+2;
            textField.delegate = self;
            textField.textAlignment = NSTextAlignmentLeft;
            [textField addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventEditingChanged];
            [subV addSubview:textField];
            UIImageView * arrowImg = [[UIImageView alloc]initWithFrame:CGRectMake(subV.frame.size.width-30, nameLab.top+20-15/2, 9, 15)];
            arrowImg.image = [UIImage imageNamed:@"all-跳转图标"];
            if (_isEditing) {
                
            }
            [subV addSubview:arrowImg];
            if (i == 0 || i == 1 || i == 2 || i == 3 || i == 4 || i==5 || i == 6 || i == 7 || i == 8 || i == 9) {
                UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
                tap.numberOfTapsRequired = 1;
                tap.numberOfTouchesRequired = 1;
                [lastSubV addGestureRecognizer:tap];
                textField.enabled = NO;
            }
        }
    }
    return sectionOne;
}
-(UIView *)createSection1View
{
    if (sectionTwo) {
        
    }
    else
    {
        sectionTwo = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 110)];
        UITextView * contentTextV = [[UITextView alloc]initWithFrame:CGRectMake(15, 5, SCREEN_WIDTH-30, 100)];
        contentTextV.tag = 12;
        contentTextV.backgroundColor = [UIColor whiteColor];
    //    contentTextV.layer.masksToBounds = YES;
    //    contentTextV.layer.borderWidth = 0.5;
        contentTextV.delegate = self;
        contentTextV.returnKeyType = UIReturnKeyDone;
    //    contentTextV.layer.borderColor = [[UIColor blackColor] CGColor];
        [sectionTwo addSubview:contentTextV];
        
        UILabel * placeHolderLab = [[UILabel alloc]initWithFrame:CGRectMake(18, 10, SCREEN_WIDTH-30, 20)];
        placeHolderLab.tag = 20;
        placeHolderLab.text = @"简单说说您的优势，可提高15%的下载机率!";
        placeHolderLab.font = [UIFont systemFontOfSize:14];
        placeHolderLab.textColor = [UIColor lightGrayColor];
        [sectionTwo addSubview:placeHolderLab];
        UILabel * placeHolderLab2 = [[UILabel alloc]initWithFrame:CGRectMake(18, 30, SCREEN_WIDTH-30, 20)];
        placeHolderLab2.tag = 21;
        placeHolderLab2.text = @"例如：职业特长、性格特点、岗位证书";
        placeHolderLab2.textColor = [UIColor lightGrayColor];
        placeHolderLab2.font = [UIFont systemFontOfSize:14];

        [sectionTwo addSubview:placeHolderLab2];
    }
    return sectionTwo;
}
#pragma mark - UITextFieldDelegate
-(void)textChange:(UITextField *)textField
{
    if (textField.tag == 1) {
        if (textField.text.length >= 40) {
            NSString * s = textField.text;
            textField.text = [s substringToIndex:40];
        }
        NSLog(@"1");
        _addResumeModel.title = textField.text;
    }
    else if (textField.tag == 2)
    {
        NSLog(@"2");
        _addResumeModel.realname = textField.text;
    }
    else if (textField.tag == 3)
    {
        NSLog(@"3");
        _addResumeModel.sex = textField.text;
    }
    else if (textField.tag == 4)
    {
        NSLog(@"4");
        _addResumeModel.tel = textField.text;
    }
    else if (textField.tag == 5)
    {
        NSLog(@"5");
        _addResumeModel.workyear = textField.text;
    }
    else if (textField.tag == 6)
    {
        NSLog(@"6");
        _addResumeModel.birthday = textField.text;
    }
    else if (textField.tag == 7)
    {
        NSLog(@"7");
        _addResumeModel.nowaddr = textField.text;

    }
    else if (textField.tag == 8)
    {
        NSLog(@"8");
        _addResumeModel.workcity = textField.text;

    }
    else if (textField.tag == 9)
    {
        NSLog(@"9");
        _addResumeModel.homeaddr = textField.text;

    }
    else if (textField.tag == 10)
    {
        NSLog(@"10");
        _addResumeModel.dutyid = textField.text;

    }
    else if (textField.tag == 11)
    {
        NSLog(@"11");
        _addResumeModel.salary = textField.text;
    }
}
-(void)textViewDidChange:(UITextView *)textView
{
    NSLog(@"textView");
    if ([textView.text isEqualToString:@""]) {
        for (int i = 0; i< 2; i++) {
            UILabel * lab = (UILabel *)[self.view viewWithTag:i+20];
            lab.hidden = NO;
        }
    }
    else
    {
        for (int i = 0; i< 2; i++) {
            UILabel * lab = (UILabel *)[self.view viewWithTag:i+20];
            lab.hidden = YES;
        }
    }
    _addResumeModel.intro = textView.text;
}
-(void)saveBtnAction:(id)sender
{
    if ([self isLogin]) {
        if (_isEditing) {
            NSLog(@"编辑保存数据");
            if (![self dealInformation]) {
                return;
            }
            
            //此处上传服务器
            _addResumeModel.code = [Singleton share].code;
            _addResumeModel.rid = _rid;
            [self modifyResumeWithmodel:_addResumeModel];
            
        }
        else
        {
           // UITextField * dutyField = (UITextField *)[self.view viewWithTag:10];
            
            _addResumeModel.code = [Singleton share].code;
            if (![self dealInformation]) {
                return;
            }
            //此处上传服务器
            
            
            [self resumeAddWithAction:_addResumeModel];
        }
    }
    
    
}
-(BOOL)isLogin
{
    if ([Singleton share].code) {
        NSLog(@"登录了");
        return YES;
        
    }
    else
    {
        //        NSLog(@"还没登录呢");
        //        LoginViewController * loginVC = [[LoginViewController alloc]init];
        //        [self.navigationController pushViewController:loginVC animated:NO];
        //        return NO;
        if (SYSTEM_VERSION >= 8.0) {
            UIAlertController * alerVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您还没有登录是否登录" preferredStyle:UIAlertControllerStyleAlert];
            [alerVC addAction:[UIAlertAction actionWithTitle:@"登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                
                LoginViewController * loginVC = [[LoginViewController alloc]init];
                UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:loginVC];
                nvc.navigationBarHidden = YES;
                
                [self presentViewController:nvc animated:YES completion:nil];
            }]];
            [alerVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                
            }]];
            [self.view.window.rootViewController presentViewController:alerVC animated:YES completion:nil];
            
        }
        else
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您还没有登录是否登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert show];
        }
        return NO;
        
    }
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    int i = (int)buttonIndex;
    if (i == 0) {
        
    }
    else if(i == 1)
    {
        LoginViewController * loginVC = [[LoginViewController alloc]init];
        UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:loginVC];
        nvc.navigationBarHidden = YES;
        
        [self presentViewController:nvc animated:YES completion:nil];
    }
}
-(void)selectedAction:(UIButton *)btn
{
    if (btn.selected == YES) {
        btn.selected = NO;
        _addResumeModel.ispic = @"0";
    }
    else
    {
        btn.selected = YES;
        _addResumeModel.ispic = @"1";
        UIActionSheet * sheet = [[UIActionSheet alloc]initWithTitle:@"选择上传图片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"默认全部",@"部分同步",nil];
        [sheet showInView:self.view];
    }
}

-(BOOL)dealInformation{
    if (!_addResumeModel.title || [_addResumeModel.title isEqualToString:@""]) {
        [Singleton alerSendMessage:@"请填写简历名称"];
        return NO;
    }
    if (!_addResumeModel.realname || [_addResumeModel.realname isEqualToString:@""]) {
        [Singleton alerSendMessage:@"请填写姓名"];
        return NO;
    }
    if (!_addResumeModel.sex) {
        [Singleton alerSendMessage:@"请填写性别"];
        return NO;
    }
    if (!_addResumeModel.tel || [_addResumeModel.tel isEqualToString:@""]) {
        [Singleton alerSendMessage:@"请填写联系电话"];
        return NO;
    }
    if (!_addResumeModel.workyear) {
        [Singleton alerSendMessage:@"请填写工作年限"];
        return NO;
    }
    if (!_addResumeModel.birthday) {
        [Singleton alerSendMessage:@"请填写出生日期"];
        return NO;
    }
    if (!_addResumeModel.nowaddr) {
        [Singleton alerSendMessage:@"请填写现居住地"];
        return NO;
    }
    if (!_addResumeModel.workcity) {
        [Singleton alerSendMessage:@"请填写想工作地"];
        return NO;
    }
    if (!_addResumeModel.homeaddr) {
        [Singleton alerSendMessage:@"请填写籍贯"];
        return NO;
    }
    if (!_addResumeModel.dutyid) {
        [Singleton alerSendMessage:@"请填写职位类别"];
        return NO;
    }
    if (!_addResumeModel.salary) {
        [Singleton alerSendMessage:@"请填写薪资"];
        return NO;
    }
    if (!_addResumeModel.intro || [_addResumeModel.intro isEqualToString:@""]) {
        [Singleton alerSendMessage:@"请填写个人简介"];
        return NO;
    }
    return YES;
}
#pragma mark - 点击手势实现方法
-(void)tapAction:(UITapGestureRecognizer *)tap
{
    UIView * lastSubV = (UIView *)tap.view;
    
    int tag = (int)lastSubV.tag;
    if (tag == 100) {
        NameViewController * nameVC = [[NameViewController alloc]init];
        nameVC.delegate = self;
        [self.navigationController pushViewController:nameVC animated:YES];
    }
    if (tag == 101) {
        UIActionSheet * sheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"男",@"女", nil];
        sheet.tag = 712;
        [sheet showInView:self.view];
    }
    if (tag == 102) {
        PhoneNumberViewController * numberVC = [[PhoneNumberViewController alloc]init];
        numberVC.delegate = self;
        [self.navigationController pushViewController:numberVC animated:YES];
    }
    if (tag == 103) {
        WorkYearsViewController * workYearsVC = [[WorkYearsViewController alloc]init];
        workYearsVC.delegate = self;
        [self.navigationController pushViewController:workYearsVC animated:YES];
    }
    if (tag == 104) {
        NSDate * now = [NSDate date];
        NSCalendar * calendar = [NSCalendar currentCalendar];
        NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
        NSDateComponents * dateComponent = [calendar components:unitFlags fromDate:now];
        int year = (int)[dateComponent year];
        NSMutableArray * yearArr = [[NSMutableArray alloc]init];
        for (int i = year-100; i<=year; i++ ) {
            
            [yearArr addObject:[NSString stringWithFormat:@"%i",i]];
            
        }
        NSMutableArray * riArr = [[NSMutableArray alloc]init];
        for (int i = 1; i<=31; i++) {
            if (i<10) {
                [riArr addObject:[NSString stringWithFormat:@"0%i",i]];
            }
            else
            {
                [riArr addObject:[NSString stringWithFormat:@"%i",i]];
            }
        }
        [WheelView wheelViewThreeComponentWithTitle:@"出生日期" leftArray:yearArr midArray:@[@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12"] rightArray:riArr andSelectState:@[@"50"] Block:^(NSString *element0, NSString *element1, NSString *element2) {
            NSArray * arr = @[element0,element1,element2];
            NSString * str = [arr componentsJoinedByString:@""];
            _addResumeModel.birthday = str;
            NSString * dateStr = [arr componentsJoinedByString:@"-"];
            UITextField * textField = (UITextField *)[self.view viewWithTag:6];
            textField.text = dateStr;
        }];

    }
    if (tag == 105) {
        ChosePrivinceViewController * chosePrivinceVC = [[ChosePrivinceViewController alloc]init];
        chosePrivinceVC.delegate = self;
        chosePrivinceVC.tag = 7;
        [self.navigationController pushViewController:chosePrivinceVC animated:YES];
    }
    if (tag == 106) {
        ChosePrivinceViewController * chosePrivinceVC = [[ChosePrivinceViewController alloc]init];
        chosePrivinceVC.delegate = self;
        chosePrivinceVC.tag = 8;
        [self.navigationController pushViewController:chosePrivinceVC animated:YES];
    }
    if (tag == 107) {
        ChosePrivinceViewController * chosePrivinceVC = [[ChosePrivinceViewController alloc]init];
        chosePrivinceVC.delegate = self;
        chosePrivinceVC.tag = 9;
        [self.navigationController pushViewController:chosePrivinceVC animated:YES];
    }
    if (tag == 108) {
        ChosePositionViewController * chosePositionVC = [[ChosePositionViewController alloc]init];
        [self.navigationController pushViewController:chosePositionVC animated:YES];
    }
    if (tag == 109) {
        HopeMoneyViewController * hopemoneyVC = [[HopeMoneyViewController alloc]init];
        hopemoneyVC.delegate = self;
        [self.navigationController pushViewController:hopemoneyVC animated:YES];
    }
    
}
-(void)tapActionThree:(UITapGestureRecognizer *)tap
{
    if (![_addResumeModel.ispic isEqualToString:@"0"]) {
        UIActionSheet * sheet = [[UIActionSheet alloc]initWithTitle:@"选择上传图片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"部分同步",nil];
        [sheet showInView:self.view];
    }
}
-(void)tapActionTwo:(UITapGestureRecognizer *)tap
{
    if (![_addResumeModel.ispic isEqualToString:@"0"]) {
        UIActionSheet * sheet = [[UIActionSheet alloc]initWithTitle:@"选择上传图片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"全部",@"部分同步",nil];
        [sheet showInView:self.view];
    }
}
#pragma mark - 自定义代理方法的实现
-(void)choseWorkYearsWith:(NSString *)years andId:(NSString *)yearId
{
    UITextField * textField = (UITextField *)[self.view viewWithTag:5];
    _addResumeModel.workyear = yearId;
    textField.text = years;
}
-(void)selectePrivince:(NSString *)privince andids:(NSString *)ids withTag:(int)tag
{
    NSLog(@"tag:%i",tag);
    if (tag == 7) {
        UITextField * textField = (UITextField *)[self.view viewWithTag:7];
        textField.text = privince;
        _addResumeModel.nowaddr = ids;
    }
    else if (tag == 8)
    {
        UITextField * textField = (UITextField *)[self.view viewWithTag:8];
        textField.text = privince;
        _addResumeModel.workcity = ids;
    }
    else
    {
        UITextField * textField = (UITextField *)[self.view viewWithTag:9];
        textField.text = privince;
        _addResumeModel.homeaddr = ids;
    }
}
-(void)choosePSQNoti:(NSNotification *)noti
{
//    NSDictionary * dic = @{@"ids":model.Ids,@"tag":[NSNumber numberWithInt:_tag],@"typenames":model.typenames};

    NSDictionary * dic = noti.object;
    int tag = [[dic objectForKey:@"tag"] intValue];
    NSString * privince =[dic objectForKey:@"typenames"];
    NSString * ids = [dic objectForKey:@"ids"];
    if (tag == 7) {
        UITextField * textField = (UITextField *)[self.view viewWithTag:7];
        textField.text = privince;
        _addResumeModel.nowaddr = ids;
    }
    else if (tag == 8)
    {
        UITextField * textField = (UITextField *)[self.view viewWithTag:8];
        textField.text = privince;
        _addResumeModel.workcity = ids;
    }
    else
    {
        UITextField * textField = (UITextField *)[self.view viewWithTag:9];
        textField.text = privince;
        _addResumeModel.homeaddr = ids;
    }

}
-(void)choseHopeMoneywithStr:(NSString *)hopemoneyStr andHopemoneyId:(NSString *)hopemoneyId
{
    UITextField * textField = (UITextField *)[self.view viewWithTag:11];
    _addResumeModel.salary = hopemoneyId;
    textField.text = hopemoneyStr;
}
-(void)changNameWithStr:(NSString *)name
{
    UITextField * textField = (UITextField *)[self.view viewWithTag:2];
    _addResumeModel.realname = name;
    textField.text = name;
}
-(void)changePhoneNumberWithnumber:(NSString *)number
{
    UITextField * textField = (UITextField *)[self.view viewWithTag:4];
    _addResumeModel.tel = number;
    textField.text = number;
}
#pragma mark - tongbuDelegate
-(void)tongbuAlummypic:(NSString *)mypic
{
    NSLog(@"mypic is %@",mypic);
    _addResumeModel.mypics = mypic;
}
#pragma mark - 消息通知的监听实现方法
-(void)selectedZhiweiNotification:(NSNotification *)noti
{
    UITextField * textField = (UITextField *)[self.view viewWithTag:10];
    NSDictionary * dic = noti.object;
    _addResumeModel.dutyid = [dic objectForKey:@"ids"];
    NSLog(@"创建简历时的消息通知***********");
    textField.text = [dic objectForKey:@"typenames"];
}
#pragma mark - actionSheetDelegate
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"%i",(int)buttonIndex);
    if (actionSheet.tag == 712) {
        UITextField * textField = (UITextField *)[self.view viewWithTag:3];
        if (buttonIndex == 0) {
            textField.text = @"男";
            _addResumeModel.sex = @"1";
        }
        else if (buttonIndex == 1)
        {
            _addResumeModel.sex = @"2";
            textField.text = @"女";
        }
    }
    else
    {
        if (buttonIndex == 0) {
            [self getAlumData];
        }
        else if (buttonIndex == 1)
        {
            //待定
            PartAlumViewController * partalumVC = [[PartAlumViewController alloc]init];
            if (![_addResumeModel.ispic isEqualToString:@"0"]) {
                partalumVC.mypic = _addResumeModel.mypics;
                partalumVC.delegate = self;
            }
            else
            {
                
            }
            [self.navigationController pushViewController:partalumVC animated:YES];
        }
    }
    
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField endEditing:YES];
    return YES;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
#pragma mark - 获取键盘动态高度
- (void) registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardWillHideNotification object:nil];
}

- (void) keyboardWasShown:(NSNotification *) notif
{
    NSDictionary *info = [notif userInfo];
    NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    //    [UIView animateWithDuration:0.05 animations:^{
    //        _tableView.frame = CGRectMake(0, -keyboardSize.height+64, SCREEN_WIDTH, SCREEN_HEIGHT-64);
    //
    //    } completion:nil];
    NSLog(@"keyBoard:%f", keyboardSize.height);  //216
    ///keyboardWasShown = YES;
    // 获取键盘动画时间
    CGFloat animationTime  = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    UITextField * textField = (UITextField *)[self.view viewWithTag:1];
    if (textField.isFirstResponder == YES) {
        
    }
    else
    {
        // 定义好动作
        void (^animation)(void) = ^void(void) {
            _tableView.transform = CGAffineTransformMakeTranslation(0, - keyboardSize.height);
        };
        
        if (animationTime > 0) {
            [UIView animateWithDuration:animationTime animations:animation];
        } else {
            animation();
        }
    }
    
}
- (void) keyboardWasHidden:(NSNotification *) notif
{
    NSDictionary *info = [notif userInfo];
    
    NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    NSLog(@"keyboardWasHidden keyBoard:%f", keyboardSize.height);
    //    [UIView animateWithDuration:0.1 animations:^{
    //        _tableView.frame = CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64);
    //
    //    } completion:nil];
    
    // keyboardWasShown = NO;
    CGFloat animationTime  = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    
    UITextField * textField = (UITextField *)[self.view viewWithTag:1];
    if (textField.isFirstResponder == YES) {
        
    }
    else
    {
        // 定义好动作
        void (^animation)(void) = ^void(void) {
            _tableView.transform = CGAffineTransformIdentity;
        };
        
        if (animationTime > 0) {
            [UIView animateWithDuration:animationTime animations:animation];
        } else {
            animation();
        }
    }
    
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    UITextField * textField = (UITextField *)[self.view viewWithTag:1];
    if (textField.editing == YES) {
        [textField resignFirstResponder];
    }
    
    UITextView * textView = (UITextView *)[self.view viewWithTag:12];
    if (textView.editable == YES) {
        [textView resignFirstResponder];
    }
    
}

#pragma  mark - 返回按钮图标
-(void)addBackItem{
    UIButton * backItem = [UIButton buttonWithType:UIButtonTypeCustom];
    backItem.frame = CGRectMake(0, 0, 9, 17);
    [backItem setImage:[UIImage imageNamed:@"返回图标"] forState:UIControlStateNormal];
    [backItem addTarget:self action:@selector(backItem:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backItem];
}
-(void)backItem:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
    
    [self.navigationController  popViewControllerAnimated:YES];
}
//#pragma mark - NAVgationBarTitle
//-(void)addNavgationBar
//{
//    UILabel * titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 120, 30)];
//    titleLab.textAlignment = NSTextAlignmentCenter;
//    titleLab.font = HeitiFont(18);
//    titleLab.text = ;
//    self.navigationItem.titleView = titleLab;
//}
#pragma mark - addRightItem
-(void)addRightItem
{
    UIButton * scanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    scanBtn.frame = CGRectMake(0, 0, 50, 30);
    [scanBtn setTitle:@"预览" forState:UIControlStateNormal];
    [scanBtn setTitleColor:UIColorFromRGB(0x6ec844) forState:UIControlStateNormal];
    [scanBtn addTarget:self action:@selector(scanBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc]initWithCustomView:scanBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
}
-(void)scanBtnAction:(UIButton *)btn
{
//    if (![self dealInformation]) {
//        [Singleton alerSendMessage:@"请完善好信息"];
//        return;
//    }
    
    UITextField * sexField = (UITextField *)[self.view viewWithTag:3];
    scanResumeModel.sex = sexField.text;
    
    UITextField * workYearField = (UITextField *)[self.view viewWithTag:5];
    
    UITextField * birthdayField = (UITextField *)[self.view viewWithTag:6];
    
    UITextField * noaddrField = (UITextField *)[self.view viewWithTag:7];
    
    UITextField * workCityField = (UITextField *)[self.view viewWithTag:8];
    
    UITextField * homeAddrField = (UITextField *)[self.view viewWithTag:9];
    
    UITextField * dutyField = (UITextField *)[self.view viewWithTag:10];
    
    UITextField * salaryField = (UITextField *)[self.view viewWithTag:11];

    
    //此处预览
//    NSDictionary * dic = @{@"code":[Singleton share].code,@"rid":_addResumeModel.rid,@"title":_addResumeModel.title,@"workyear":workYearField.text,@"birthday":birthdayField.text,@"nowaddr":noaddrField.text,@"workcity":workCityField.text,@"homeaddr":homeAddrField.text,@"dutyid":dutyField.text,@"salary":salaryField.text,@"intro":_addResumeModel.intro,@"realname":_addResumeModel.realname,@"tel":_addResumeModel.tel,@"sex":sexField.text,@"mypics":_addResumeModel.mypics,@"ispic":_addResumeModel.ispic};
    scanResumeModel = [[ResumeAddModel alloc]init];
    scanResumeModel.code = _addResumeModel.code;
    scanResumeModel.rid = _addResumeModel.rid;
    scanResumeModel.title = _addResumeModel.title;
    scanResumeModel.workyear = workYearField.text;
    scanResumeModel.birthday = birthdayField.text;
    scanResumeModel.nowaddr = noaddrField.text;
    scanResumeModel.workcity = workCityField.text;
    scanResumeModel.homeaddr = homeAddrField.text;
    scanResumeModel.dutyid = dutyField.text;
    scanResumeModel.salary = salaryField.text;
    scanResumeModel.intro = _addResumeModel.intro;
    scanResumeModel.realname = _addResumeModel.realname;
    scanResumeModel.tel = _addResumeModel.tel;
    scanResumeModel.sex = sexField.text;
    scanResumeModel.mypics = _addResumeModel.mypics;
    scanResumeModel.ispic = _addResumeModel.ispic;
    
    ScanResumeViewController *scanresumeVC = [[ScanResumeViewController alloc]init];
    scanresumeVC.addResumeModel = scanResumeModel;
    [self.navigationController pushViewController:scanresumeVC animated:YES];
    
    
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
